<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>ECharts 饼形图示例</title>
  <script src="https://cdn.jsdelivr.net/npm/echarts@5.2.2/dist/echarts.min.js"></script>
  <style type="text/css">
    .align-center{
      margin:0 auto; /* 居中 这个是必须的，其它的属性非必须 */
      width:500px;
      text-align:center; /* 文字等内容居中 */
    }
  </style>
</head>
<body>
<div id="pieChart" style="width: 900px;height:600px;padding-top: 10%" class="align-center"></div>
<div id="pieChart1" style="width: 900px;height:600px;padding-top: 10%" class="align-center"></div>
<script src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script src="${ctxPath}/assets/js/common.js"></script>
<script>
  var chartData = '';
  layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate'], function () {
    var admin = layui.admin;
    var xnUtil = layui.xnUtil;

    admin.req(getProjectUrl() + 'repair/tongji', function(res) {
        chartData = res.data.map(item => ({
          name: xnUtil.rendDataTableDict(item.comId, 'repair_type'),
          value: item.count
        }));
      const comIdList = chartData.map(({name}) => name);
      // 初始化echarts实例
      var myChart = echarts.init(document.getElementById('pieChart'));

      // 配置图表选项
      var option = {
        title: {
          text: '报修列表类型统计',
          subtext: '----',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          data: comIdList,

          left: 10
        },
        series: [
          {
            name: '报修类型',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: chartData
          }
        ]
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    }, 'get', {async:false});

    admin.req(getProjectUrl() + 'propertyInfo/tongji', function(res) {
      chartData = res.data.map(item => ({
        name: item.houseId,
        value: item.money
      }));
      const houseIdList = chartData.map(({name}) => name);
      const jineList = chartData.map(({value}) => value);

      var myChart = echarts.init(document.getElementById('pieChart1'));

      var option = {
        title: {
          text: '物业收费统计',
          left: 'center'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: houseIdList,
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '金额',
            type: 'bar',
            barWidth: '60%',
            data: jineList
          }
        ]
      };
      myChart.setOption(option);
    }, 'get', {async:false});
  });




</script>
</body>
</html>